<!DOTTYPE>
<html>
	<head>
		<meta charset="utf-8">
		<title>日历</title>
	</head>
	<body>
		<center>
			<?php
				//获取我们需要的信息
				//获取年数
				$year = isset($_GET['y'])?$_GET['y']:date("Y");
				//获取我们的月
				$month = isset($_GET['m'])?$_GET['m']:date("m");
				//测试代码
				// echo $year;
				// echo $month;
				//获取需要查看的日期到底有多少天
				$days = date("t",mktime(17,15,15,$month,1,$year));
				$week = date("w",mktime(17,15,15,$month,1,$year));
				// echo $week;
				echo "<h2>{$year}年{$month}月日历";
				?>
				<br>
				<h2>日历</h2>
				<br>
				<table border="1">
				<tr>
					<th>星期日</th>
					<th>星期一</th>
					<th>星期二</th>
					<th>星期三</th>
					<th>星期四</th>
					<th>星期五</th>
					<th>星期六</th>
				</tr>
				<?php
					//循环输出日期
					$d = 1;    //每个月初始的天数
					//循环输出一个月的天数
					while($d<=$days){
						echo "<tr>";
						//七天一个循环
						for($i = 0; $i <7; $i ++){
							if($d <= $days &&($i>=$week||$d>1)){
								echo "<td>{$d}</td>";
								$d++;
							}else{
								echo "<td>&nbsp;</td>";
							}
						}
						echo "</tr>";
					}
					?>
				</table>
		</center>
	</body>
</html>